package com.gitee.melin.bee.core.jdbc.relational;

import com.gitee.melin.bee.core.jdbc.enums.ColumnType;
import java.io.Serializable;
import lombok.Data;

@Data
public class BeeMetaColumn implements Serializable {

    private static final long serialVersionUID = 6438514547501611599L;

    private String columnName; // 小写

    private ColumnType columnType;

    private String comment;

    private boolean autoIncrement;

    private Object defaultValue;

    private boolean nullable = true;

    private Integer position;

    private Long columnLength;

    private Long precision;

    private Integer scale;

    protected BeeMetaColumn() {}

    public static BeeMetaColumn of(MetaColumn column, ColumnType columnType) {
        BeeMetaColumn metadataColumn = new BeeMetaColumn();
        metadataColumn.setColumnName(column.getColumnName());
        metadataColumn.setColumnType(columnType);
        metadataColumn.setComment(column.getComment());
        metadataColumn.setAutoIncrement(column.isAutoIncrement());
        metadataColumn.setDefaultValue(column.getDefaultValue());
        metadataColumn.setNullable(column.getNullable());
        metadataColumn.setPosition(column.getPosition());
        metadataColumn.setColumnLength(column.getLength());
        metadataColumn.setPrecision(column.getPrecision());
        metadataColumn.setScale(column.getScale());
        return metadataColumn;
    }
}
